/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tetris_invader.windows;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import tetris_invader.util.Fase;

public class Menu extends JDialog {

    private Frame frame;
    protected JMenuBar menu;
    protected JMenuItem mainMenu;
    protected JMenuItem newGame;
    protected JMenuItem save;
    protected JMenuItem load;
    protected JMenuItem exit;
    protected JMenuItem play;
    protected JMenuItem credit;
    private Fase fase;

    public Menu(Frame frame, Fase fase) {

        this.frame = frame;
        this.fase = fase;
        menu = new JMenuBar();

        JMenu game = new JMenu("Game");
        JMenu help = new JMenu("Help");

        mainMenu = new JMenuItem("Main Menu", 'M');
        newGame = new JMenuItem("New Game", 'N');
        save = new JMenuItem("Save Game", 'S');
        load = new JMenuItem("Load Game", 'L');
        exit = new JMenuItem("Exit", 'X');
        play = new JMenuItem("How to Play", 'P');
        credit = new JMenuItem("Credits");

        game.add(mainMenu);
        game.addSeparator();
        game.add(newGame);
        game.add(save);
        game.add(load);
        game.addSeparator();
        game.add(exit);
        help.add(play);
        help.addSeparator();
        help.add(credit);

        menu.add(game);
        menu.add(help);

        setJMenuBar(menu);
    }

    public Frame getFrame() {
        return frame;
    }

    public void setFrame(Frame frame) {
        this.frame = frame;
    }

    public void addListener(ActionListener ouveMenu){
        mainMenu.addActionListener(ouveMenu);
        newGame.addActionListener(ouveMenu);
        save.addActionListener(ouveMenu);
        load.addActionListener(ouveMenu);
        exit.addActionListener(ouveMenu);
        play.addActionListener(ouveMenu);
        credit.addActionListener(ouveMenu);
    }
//
//    class Ouvinte implements ActionListener {
//
//        public void actionPerformed(ActionEvent e) {
//
//            if (e.getSource() instanceof JMenuItem) {
//                String arg = e.getActionCommand();
//
//                if (arg.equals("Exit")) {
//                    int x = JOptionPane.showConfirmDialog(null, "Are you sure???\n"
//                            + "Your current data will be lost!",
//                            "Exit", JOptionPane.OK_CANCEL_OPTION,
//                            JOptionPane.WARNING_MESSAGE);
//                    if (x == JOptionPane.OK_OPTION) {
//                        System.exit(1);
//                    }
//
//                } else if (arg.equals("New Game")) {
//                    int x = JOptionPane.showConfirmDialog(null, "You will start a new game!\n"
//                            + "Your current data will be lost!",
//                            "New Game", JOptionPane.OK_CANCEL_OPTION,
//                            JOptionPane.WARNING_MESSAGE);
//                    if (x == JOptionPane.OK_OPTION) {
//                        frame.restart();
//                    }
//
//                } else if (arg.equals("Save Game")) {
//                    JOptionPane.showMessageDialog(null, "Game Saved!", "Save Game",
//                            JOptionPane.WARNING_MESSAGE);
//                    fase.save();
//                } else if (arg.equals("Load Game")) {
//                    int opt = JOptionPane.showConfirmDialog(null, "You current game will be lost.\n"
//                            + "Do yo want to continue?", "Load Game",
//                            JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
//                    if (opt == JOptionPane.YES_OPTION) {
//                        fase.recover();
//                    }
//                } else if (arg.equals("How to Play")) {
//                    JOptionPane.showConfirmDialog(null, "Use the direcional pad to control"
//                            + " your nave.\nBe careful with the invaders and destruct"
//                            + " them firing with space bar!\n Note the energy bar in the Info Panel."
//                            + "When it get full, you can fire a special beam pressing Z button!\n\n"
//                            + "Good Game!",
//                            "How to Play",
//                            JOptionPane.OK_OPTION,
//                            JOptionPane.INFORMATION_MESSAGE);
//                } else if (arg.equals("Credits")) {
//                    JOptionPane.showConfirmDialog(null, "Created by:\n"
//                            + "Rafael Umino Nakanishi and\n"
//                            + "Tamires Harumi Dantas Takehara\n\n"
//                            + "University of Sao Paulo\n"
//                            + "Summer 2010", "Credits",
//                            JOptionPane.OK_OPTION,
//                            JOptionPane.INFORMATION_MESSAGE);
//                } else if (arg.equals("Main Menu")) {
//                    int opt = JOptionPane.showConfirmDialog(null, "You will go to Main Menu!\n"
//                            + "Current game will be lost. Do you want to save?", "Main Menu",
//                            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
//
//                    if (opt == JOptionPane.YES_OPTION) {
//                        frame.mainMenu();
//                    }
//                }
//                //TODO pegar a informacao e tratar qual a opcao do usuario.
//            }
//        }
//    }
}
